local sanchen = fk.CreateSkill{
    name = "ld__sanchen",
}

Fk:loadTranslationTable{
  ["ld__sanchen"] = "三陈",
  [":ld__sanchen"] = "出牌阶段每名角色限一次，若你的武将牌均明置，你可以令一名角色摸三张牌并弃置三张牌，若其以此法弃置了类别相同的牌，你暗置此武将牌。",

  ["#ld__sanchen"] = "三陈：令一名角色摸三张牌并弃置三张牌",
  ["#ld__sanchen-discard"] = "三陈：弃置三张牌，若类别相同，则 %src 暗置武将牌",

  ["$ld__sanchen1"] = "陈书弼国，当一而再、再而三。",
  ["$ld__sanchen2"] = "勘除弼事，三陈而就。",
}

local H = require "packages.ol_hegemony.util"

sanchen:addEffect("active", {
  anim_type = "drawcard",
  prompt = "#ld__sanchen",
  card_num = 0,
  target_num = 1,
  card_filter = Util.FalseFunc,
  can_use = function (self, player)
    return H.allGeneralsRevealed(player)
  end,
  target_filter = function(self, player, to_select, selected)
    return #selected == 0 and not table.contains(player:getTableMark("ld__sanchen-turn"), to_select.id)
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    room:addTableMark(player, "ld__sanchen-turn", target.id)
    target:drawCards(3, sanchen.name)
    local cards = room:askToDiscard(target, {
      min_num = 3,
      max_num = 3,
      include_equip = true,
      skill_name = sanchen.name,
      prompt = "#ld__sanchen-discard:"..player.id,
      cancelable = false,
      skip = true,
    })
    local typeMap = {}
    for _, id in ipairs(cards) do
      typeMap[tostring(Fk:getCardById(id).type)] = (typeMap[tostring(Fk:getCardById(id).type)] or 0) + 1
    end
    room:throwCard(cards, sanchen.name, target, target)
    for _, v in pairs(typeMap) do
      if v >= 2 then
        if not player.dead then
            local isDeputy = H.inGeneralSkills(player, sanchen.name)
            if isDeputy then
              H.hideBySkillName(player, sanchen.name, isDeputy == "d")
          end
        end
      end
    end
  end,
})

return sanchen